<?php
if (isset($_POST['doService_comp'])) {
    //adhésion
    if (isset($_POST['adhesion'])) {
        
    }

    if (isset($_POST['service_RDV'])) {
        $service_RDV = $_POST['service_RDV'];
        for ($i = 0; $i < count($service_RDV); $i++) {
            $idRDV = $service_RDV[$i];
            if (intval($_POST['nb_RDV' . $idRDV]) > 0) {
                $nbRDV = $_POST['nb_RDV' . $idRDV];
                $rqt_add_RDV = "INSERT INTO commanderdv (idCommande,idRDV,NombreRDV) values (" . $_SESSION['commandeEnCours'] . "," . $idRDV . "," . $nbRDV . ")";
                mysql_query($rqt_add_RDV) or die("Erreur : " . $rqt_add_RDV);
            }
        }
    }

    if (isset($_POST['service_AccesPlateforme'])) {

        $service_AP = $_POST['service_AccesPlateforme'];
        for ($i = 0; $i < count($service_AP); $i++) {
            $idAP = $service_AP[$i];
            if (intval($_POST['nb_AccesPlateforme' . $idAP]) > 0) {
                $nbAP = $_POST['nb_AccesPlateforme' . $idAP];
                $rqt_add_AP = "INSERT INTO commandeAccesPlateforme (idCommande,idAccesPlateforme,NombreAcces) values (" . $_SESSION['commandeEnCours'] . "," . $idAP . "," . $nbAP . ")";
                mysql_query($rqt_add_AP) or die("Erreur : " . $rqt_add_AP);
            }
        }
    }
    maj_cout_commande($_SESSION['commandeEnCours']);
    header("Location: index.php?page=confirm_commande");
}

//Si commande non relié à un utilisateur
?>


<h3 style="text-align: justify">Souhaitez-vous :</h3>
<form action="index.php?page=service_comp_journee" method="post" name="service_comp" id="service_comp"> 
<?php
include 'pages/services/adhesion/proposition_adhesion.php';
?>
    <div class="ligneserviceCATEL">    
    <?php
    echo '<table width="100%"><tr><td></td><td></td><td><b>Nombre</b></td><td><b>Tarif adhérent</b></td><td><b>Tarif Non adhérent</b></td>';

//RDV

    $rqt_service_rdv = "SELECT idRDV, intituleRDV, descriptionRDV FROM RDV";
    $res_service_rdv = mysql_query($rqt_service_rdv);

    while (list($idRDV, $intituleRDV, $descriptionRDV) = mysql_fetch_array($res_service_rdv)) {
        $rqt_tarif_adh = "SELECT tarifHT FROM tarif as t LEFT JOIN tarif_statut as ts ON  t.idTarif=ts.idTarif WHERE ts.idStatut=1 AND t.idRDV=" . $idRDV;
        $res_tarif_adh = mysql_query($rqt_tarif_adh);
        list($tarifAdh) = mysql_fetch_array($res_tarif_adh);
        $rqt_tarif_nadh = "SELECT tarifHT FROM tarif as t LEFT JOIN tarif_statut as ts ON  t.idTarif=ts.idTarif WHERE ts.idStatut=4 AND t.idRDV=" . $idRDV;
        $res_tarif_nadh = mysql_query($rqt_tarif_nadh);
        list($tarifNAdh) = mysql_fetch_array($res_tarif_nadh);

        echo '<tr><td><input type="checkbox" name="service_RDV[]" value="' . $idRDV . '" id="serviceRDV"></td><td>' . utf8_encode($intituleRDV) . '<br><i>' . utf8_encode($descriptionRDV) . '</i></input></td><td><select style="width:40px" name="nb_RDV' . $idRDV . '">
                    <option>0</option>
                    <option>1</option>
                    <option>2</option>
                    <option>3</option>
                    <option>4</option>
                    <option>5</option>
                    <option>6</option>
                    <option>7</option>
                    <option>8</option>
                    <option>9</option>
                    <option>10</option>
                    </select></td><td>' . $tarifAdh . '€ HT</td><td>' . $tarifNAdh . '€ HT</td></tr>';
    }



//Accès Plateforme
    $rqt_service_AccesPlateforme = "SELECT idAccesPlateforme, intituleAccesPlateforme, descriptionAccesPlateforme FROM AccesPlateforme";
    $res_service_AccesPlateforme = mysql_query($rqt_service_AccesPlateforme);

    while (list($idAccesPlateforme, $intituleAccesPlateforme, $descriptionAccesPlateforme) = mysql_fetch_array($res_service_AccesPlateforme)) {
        $rqt_tarif_adh = "SELECT tarifHT FROM tarif as t LEFT JOIN tarif_statut as ts ON  t.idTarif=ts.idTarif WHERE ts.idStatut=1 AND t.idAccesPlateforme=" . $idAccesPlateforme;
        $res_tarif_adh = mysql_query($rqt_tarif_adh);
        list($tarifAdh) = mysql_fetch_array($res_tarif_adh);
        $rqt_tarif_nadh = "SELECT tarifHT FROM tarif as t LEFT JOIN tarif_statut as ts ON  t.idTarif=ts.idTarif WHERE ts.idStatut=4 AND t.idAccesPlateforme=" . $idAccesPlateforme;
        $res_tarif_nadh = mysql_query($rqt_tarif_nadh);
        list($tarifNAdh) = mysql_fetch_array($res_tarif_nadh);

        echo '<tr style="border-bottom:1px black solid"><td><input type="checkbox" name="service_AccesPlateforme[]" value="' . $idAccesPlateforme . '" id="serviceAccesPlateforme"></td><td>' . utf8_encode($intituleAccesPlateforme) . '<br><i>' . utf8_encode($descriptionAccesPlateforme) . '</i></input></td><td><select style="width:40px" name="nb_AccesPlateforme' . $idAccesPlateforme . '">
                    <option>0</option>
                    <option>1</option>                    
                    </select></td><td>' . $tarifAdh . '€ HT</td><td>' . $tarifNAdh . '€ HT</td></tr>';
    }





    echo '</table>';
    ?>

    </div>
    <div style="text-align: right"><input name="doService_comp" type="submit" id="doService_comp" value="Continuer"/></div>
</form>
